// pages/confirm/confirm.js
Page({
  data: {
    categoryList: [],
    sum: 0,
    user_table: 0,
    HZL_my_cat: [],
    allNum: 0,
    order_remark:'',
    isCanShow: 0
  },

  getCategoryList() {
    let that = this
    wx.request({
      url: 'https://order.xiaxueruo.com/api/category/list',
      method: 'GET', //get或者post
      success: function (e) {
        that.setData({
          // categoryList: e.data.data.categoryList
        })
      }
    })
  },

  onLoad: function () {
    console.log('HZL_my_cat', wx.getStorageSync('HZL_my_cat'))
    var HZL_my_cat = wx.getStorageSync('HZL_my_cat')
    this.checkIsCanShow();
    this.getCategoryList();
    var sum = 0;
    var allNum = 0;
    for (let i = 0; i < HZL_my_cat.length; i++) {
      sum = sum + HZL_my_cat[i].num * HZL_my_cat[i].price
      allNum = allNum + HZL_my_cat[i].num
    }
    console.log(sum)
    console.log(allNum)
    console.log('user_table--------', wx.getStorageSync('user_table'))
    this.setData({
      user_table: wx.getStorageSync('user_table'),
      HZL_my_cat: wx.getStorageSync('HZL_my_cat'),
      sum: sum,
      allNum: allNum
    })
  },

  ordergoods: function () {
    let that = this
    console.log('that.data',that.data);
    console.log('foodList',JSON.stringify( wx.getStorageSync('HZL_my_cat')));
    wx.request({
      url: 'https://order.xiaxueruo.com/api/detail/add?num=' + that.data.allNum + '&order_price=' + that.data.sum + '&user_id=' +  wx.getStorageSync('user_id') + '&user_table=' +wx.getStorageSync('user_table') + '&order_status=' + '已完成' +
      '&order_remark=' + that.data.order_remark,
      data: {
        foodList: JSON.stringify( wx.getStorageSync('HZL_my_cat'))
      },
      success: function (res) {
        console.log('res',res);
        wx.showToast({
          title: '成功',
          icon: 'success',
          duration: 1000 //持续的时间
        })
        wx.navigateTo({
          url: '../confirm/pay/pay',
        })
      },
      fail: function (res) {
        console.log("失败");
      }
    })

   
    // var that = this;
    // wx.showToast({
    //   title: '提交订单成功', //提示文字
    //   duration: 1000, //显示时长
    //   mask: true, //是否显示透明蒙层，防止触摸穿透，默认：false  
    //   icon: 'success', //图标，支持"success"、"loading"  
    //   success: function () {}, //接口调用成功
    //   fail: function () {}, //接口调用失败的回调函数  
    //   complete: function () {} //接口调用结束的回调函数  
    // })

  },

  /**
   * 获取接口数据，控制是否显示敏感信息
   */
  checkIsCanShow() {
    wx.request({
      url: 'https://order.xiaxueruo.com/api/order/isCanShow/',
      success: res => {
        this.setData({
          isCanShow: res.data
        })
      }
    })
  },
})